package top.cardone.generator.code;

import lombok.extern.log4j.Log4j2;
import org.springframework.boot.SpringApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import org.springframework.util.CollectionUtils;

import java.util.Map;

/**
 * 主执行端
 *
 * @author yao hai tao
 */
@Log4j2
@ComponentScan
public class GeneratorApplication {
    /**
     * 主方法
     *
     * @param args 参数
     */
    public static void main(String[] args) {
        Map<String, PoMapperFactory> poMapperFactoryMap = new FileSystemXmlApplicationContext(new String[]{"${configLocation}"}, true, SpringApplication.run(GeneratorApplication.class, args)).getBeansOfType(PoMapperFactory.class);

        if (CollectionUtils.isEmpty(poMapperFactoryMap)) {
            return;
        }

        for (final PoMapperFactory poMapperFactory : poMapperFactoryMap.values()) {
            try {
                poMapperFactory.run();
            } catch (Exception e) {
                log.error(e.getMessage(), e);
            }
        }
    }
}
